package my.mashup;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.io.IOException;


@SpringBootApplication
public class MashupApplication {
    public static RelMap relMap = new RelMap();
    public static ApiMap apiMap = new ApiMap();

    public static void main(String[] args) throws IOException {
        // 生成 API、Mashup及两者间调用关系对应的 Map
        relMap.genAll();
        // 生成 API 调用矩阵
        apiMap.genMatrix(relMap.apiByAddr, relMap.mashupToAddrs);
        SpringApplication.run(MashupApplication.class, args);
    }

    @Bean
    public WebMvcConfigurer corsConfigurer() {
        return new WebMvcConfigurer() {
            @Override
            public void addCorsMappings(CorsRegistry registry) {
                registry.addMapping("/search").allowedOrigins("*");
                registry.addMapping("/test").allowedOrigins("*");
            }
        };
    }
}
